<el-dialog id="formUpdate" title="修改名称/编号" :visible.sync="dialogUpdateVisible" width="600px" v-cloak >
    <el-scrollbar class="ms-scrollbar" style="height: 100%;">
        <el-form ref="updateForm" :model="updateForm" :rules="updateRules" size="mini" label-width="100px" >
            <el-form-item  label="编号:" prop="fileCode">
                <el-input
                        :disabled="false"
                        :readonly="false"
                        v-model="updateForm.fileCode"
                        :style="{width: '100%'}"
                        placeholder="请输入编号">
                </el-input>
            </el-form-item>
            <el-form-item  label="文件名称:" prop="fileName">
                <el-input
                        :disabled="false"
                        :readonly="false"
                        v-model="updateForm.fileName"
                        :style="{width: '100%'}"
                        placeholder="请输入文件名称">
                </el-input>
            </el-form-item>
        </el-form>
    </el-scrollbar>
    <div slot="footer">
        <el-button size="mini" @click="dialogUpdateVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="updateConfirm()">确 认</el-button>
    </div>
</el-dialog>
<script>
    var formUpdate = new Vue({
        el: '#formUpdate',
        data: function () {
            var that = this;
            var validatorModifyFileName = function (rule,value,callback) {
                if(value ===""){
                    callback(new Error('文件名称不能为空，请输入'));
                }else if(value){
                    if(that.errorModifyMsg){
                        callback(new Error('文件名称已存在，请重新输入'));
                    }else{return callback();}
                }else{return callback();}
            };
            var validatorModifyFileCode = function (rule,value,callback) {
                if(value ===""){
                    callback(new Error('编号不能为空，请输入'));
                }else if(value){
                    if(that.errorModifyMsg){
                        callback(new Error('编号已存在，请重新输入'));
                    }else{return callback();}
                }else{return callback();}
            };
            return {
                updateForm: {
                    id:'',
                    fileCode:'',
                    fileName:''
                },
                updateRules: {
                    // 申请说明
                    fileCode: [ { "required": true, validator :validatorModifyFileCode }],
                    fileName: [ { "required": true, validator :validatorModifyFileName }],
                },
                dialogUpdateVisible:false,
                errorModifyMsg:'',
            };
        },
        watch: {
        },
        computed: {},
        methods: {
            showUpdateDialog: function(row){
                this.updateForm={ id:'', fileCode:'', fileName:''};
                this.dialogUpdateVisible=true;
                this.updateForm.id=row[0].id;
                this.updateForm.fileCode=row[0].fileCode;
                this.updateForm.fileName=row[0].fileOriginName;
                this.errorModifyMsg="";
                this.$refs.updateForm.validateField('fileName');
                this.$refs.updateForm.validateField('fileCode');
            },

            updateConfirm:function(){
                var that = this;
                that.errorModifyMsg="";
                that.$refs.updateForm.validateField('fileName');
                that.$refs.updateForm.validateField('fileCode');
                that.$refs.updateForm.validate(function (valid) {
                    if (valid) {
                        ms.http.post(ms.manager + "/cms/document/modify", that.updateForm,{
                            headers: {
                                'Content-Type': 'application/json'
                            }
                        }).then(function (res) {
                            if(res.code===200){
                                that.errorModifyMsg = "";
                                that.$notify({
                                    type: 'success',
                                    message: "修改成功"
                                });
                                //新建成功，刷新列表
                                that.dialogUpdateVisible = false;
                                indexVue.list();
                            }else{
                                that.errorModifyMsg = "修改失败";
                                that.$nextTick(function () {
                                    if(res.msg==="NAME"){
                                        that.$refs.updateForm.validateField('fileName');
                                    }else if(res.msg==="CODE"){
                                        that.$refs.updateForm.validateField('fileCode');
                                    }else if(res.msg==="ALL"){
                                        that.$refs.updateForm.validateField('fileName');
                                        that.$refs.updateForm.validateField('fileCode');
                                    }
                                })

                            }


                        }).catch(function (err) {
                            that.$notify({
                                type: 'error',
                                message: "修改失败"
                            });
                        });
                    }
                })
            },
        },
        created: function () {}
    });
</script>
<style>

</style>
